package active.observers;


import java.util.ArrayList;
import java.util.List;

public class Subject {

    private List<WeatherObserver> weatherObserverList = new ArrayList<>();

    private int state;

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        notifyAllObserver();
    }

    public void attach(WeatherObserver weatherObserver) {
        weatherObserverList.add(weatherObserver);
    }

    public void remove(WeatherObserver weatherObserver) {
        weatherObserverList.remove(weatherObserver);
    }

    private void notifyAllObserver() {
        for (WeatherObserver weatherObserver : weatherObserverList) {
            weatherObserver.update(this);
        }
    }
} 
